/*
 * SharedMemory.hpp
 *
 *  Created on: Nov 2, 2013
 *      Author: vladimir
 */

#ifndef SHAREDMEMORY_HPP_
#define SHAREDMEMORY_HPP_

#include <string>
#include <memory>

namespace vjipc {
enum class AccessType;
}

namespace vjipc
{


class SharedMemory
{
public:

	SharedMemory(
			const vjipc::AccessType & accessType,
			const std::string & name,
			const unsigned int lenght );
	~SharedMemory();

	SharedMemory( const SharedMemory& ) = delete;
	SharedMemory& operator=( const SharedMemory& ) = delete;

	SharedMemory( SharedMemory&& rhs );
	SharedMemory& operator=( SharedMemory&& rhs );


	template< typename T >
	T& Access();
	template< typename T >
	const T& Access() const;

private:

	void* GetSharedMemoryPtr() const;


	struct Imp;
	std::unique_ptr<Imp> pimpl;
};




template< typename T >
T& SharedMemory::Access()
{
	return * static_cast< T* >( GetSharedMemoryPtr() );
}

template< typename T >
const T& SharedMemory::Access() const
{
	return * static_cast< const T* >( GetSharedMemoryPtr() );
}


} /* namespace vjipc */

#endif /* SHAREDMEMORY_HPP_ */
